#!/bin/sh

# pip3 install mysql-connector-python
# pip3 install tqdm
# pip3 install openpyxl
# pip3 install pika
# pip3 install treelib

cd ../internal_server/bot/financial_sales/knowledge_base/
python3 knowledge_embedding.py

cd ../../financial_sales_first_loan/knowledge_base/
python3 knowledge_embedding.py

cd ../../financial_sales_b/knowledge_base/
python3 knowledge_embedding.py

cd ../../../../credit_voice_service/

GREP_PROCESS="python3 LLM_server.py"

##################### restart server #############################
PID_RANK=`ps -ef|grep "$GREP_PROCESS"|grep -v grep|awk '{print $2}'|xargs`
if [  "$PID_RANK" != "" ];then
    echo "-----Force kill current server process"
    kill -9 $PID_RANK
fi

echo '' >  nohup.out
echo '' >  dialogue.log
echo '' > internal_server.log
# nohup python3 LLM_server.py >> nohup.out 2>&1 &
for i in $(seq 18635 1 18640);
do
nohup python3 LLM_server.py --port=$i >> nohup.out 2>&1 &
done

################### check if server startup ##########################
PID_RANK=`ps -ef|grep "$GREP_PROCESS"|grep -v grep|awk '{print $2}'`

if [  "$PID_RANK" == "" ];then
    echo "startup fail please check log file."
    exit 1
fi

